package com.gz.logistics.app;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.gz.logistics.R;
import com.gz.logistics.adapter.ClothesDetailsAdapter;
import com.gz.logistics.fragment.OutingFragment;
import com.gz.logistics.library.IAuthor;
import com.gz.logistics.library.pojo.GetClothes;
import com.gz.logistics.library.pojo.UserInfo;
import com.gz.logistics.library.util.Constants;
import com.gz.logistics.library.util.PreferenceModel;
import com.handmark.pulltorefresh.library.PullToRefreshBase;
import com.handmark.pulltorefresh.library.PullToRefreshListView;
/**
 * author wanner1991
 */
public class ClothesDetailActivity extends BaseActivity implements View.OnClickListener {
    private String TAG = ClothesDetailActivity.class.getSimpleName();
    private UserInfo userInfo;
    private TextView tv_order_number;//订单编号
    private TextView tv_receiver_name;//客户姓名
    private TextView tv_receiver_phone;//联系方式
    private TextView tv_receiver_address;//地址
    private TextView tv_status;//衣服种类
    private TextView tv_receiver_cpucbt;//预约时间
    private TextView tv_receiver_outtime;//应收金额

    private GetClothes clothes;
    private int user_type = 0;
    private ClothesDetailsAdapter adapter;
    private PullToRefreshListView mPullList;
    public static Context context;
    private LinearLayout clothesdetial;
    private RelativeLayout cancle;//取消



    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.query_clothesdetail_item);
        setActionbarTitle("订单详情",false);
        context = getApplicationContext();
        userInfo =  IAuthor.getInstance().loadUserInfoSyn(PreferenceModel.getInt(Constants.PREFERENCE_USER_ID, -1));
        clothes = (GetClothes) getIntent().getSerializableExtra("clotheslist");
        user_type = getIntent().getIntExtra("user_type",0);
        initView();

    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
    }


    @Override
    public void onClick(View view) {
        switch (view.getId()){
            case R.id.iv_actionbar_up:
                Intent intent = new Intent(this, OutingFragment.class);
                setResult(109, intent);
                finish();
                break;
        }

    }
    /**
     * 如果店家物理返回按钮返回上一个页面， 对是否设置返回值进行判断设置
     * @param keyCode
     * @param event
     * @return
     */
    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_BACK) {
            Intent intent = new Intent(this, OutingFragment.class);
            setResult(109, intent);
            finish();
            return true;
        }
        return super.onKeyDown(keyCode, event);
    }

    private void initView() {
        tv_order_number = (TextView)findViewById(R.id.tv_order_number);
        tv_receiver_name = (TextView)findViewById(R.id.tv_receiver_name);
        tv_receiver_phone = (TextView)findViewById(R.id.tv_receiver_phone);
        tv_receiver_address = (TextView)findViewById(R.id.tv_receiver_address);
        tv_status = (TextView)findViewById(R.id.tv_status);
        tv_receiver_cpucbt = (TextView)findViewById(R.id.tv_receiver_cpucbt);
        tv_receiver_outtime = (TextView)findViewById(R.id.tv_receiver_outtime);
        mPullList = (PullToRefreshListView)findViewById(R.id.detail);
        mPullList.setMode(PullToRefreshBase.Mode.DISABLED);
        clothesdetial = (LinearLayout)findViewById(R.id.clothesdetial);

        tv_order_number.setText("预约单号："+clothes.getOrderno());
        tv_receiver_name.setText("客户姓名："+clothes.getClient());
        tv_receiver_phone.setText("联系方式："+clothes.getPhone());
        tv_receiver_address.setText("客户地址："+clothes.getAddress());
        tv_status.setText("衣服种类："+clothes.getClothgategory());
        tv_receiver_cpucbt.setText("预约时间：" + clothes.getGreservetime());
        tv_receiver_outtime.setText("应收金额：" + clothes.getMoney());

        cancle = (RelativeLayout) findViewById(R.id.cancle);

        if (clothes.getDetailses()==null){
            clothesdetial.setVisibility(View.GONE);
        }else{
            clothesdetial.setVisibility(View.VISIBLE);
            adapter = new ClothesDetailsAdapter(clothes.getDetailses(),getApplicationContext());
            mPullList.setAdapter(adapter);
            adapter.notifyDataSetChanged();
        }

    }




}
